﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Vds2465Telegrams
{
	[TestClass]
	public class UserData_30_Measurements_Test
	{
		#region equals

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test01_Equals_RepType01()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Output, eMeasurementType.Humidity, 0.5);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_11_Error userData2Compare = new UserData_11_Error(eErrorCode.DataOutOfRange, 0x99);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different representation type - otherwise as identical as possible
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
												0xee, 0xdd);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension, 
									userData.MeasurementType, userData.MeasurementValue);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different device
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements((byte) (userData.Device - 1), userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.MeasurementType, userData.MeasurementValue);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, (byte)(userData.Address - 1), userData.AddressAddOn, userData.AddressExtension,
									userData.MeasurementType, userData.MeasurementValue);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different AddressAddOn
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, (byte)(userData.AddressAddOn - 1), userData.AddressExtension,
									userData.MeasurementType, userData.MeasurementValue);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address extension
				eAddressExtension_1 addExt = eAddressExtension_1.Disruption;
				if (userData.AddressExtension == eAddressExtension_1.Disruption)
				{
					addExt = eAddressExtension_1.Input;
				}
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, addExt,
									userData.MeasurementType, userData.MeasurementValue);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different measurementType
				eMeasurementType measurementType = eMeasurementType.LightIntensity;
				if (userData.MeasurementType == eMeasurementType.LightIntensity)
				{
					measurementType = eMeasurementType.RadioactiveEnergyDose;
				}
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									measurementType, userData.MeasurementValue);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different measurementValue
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.MeasurementType, userData.MeasurementValue + 0.1);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test02_Equals_RepType02()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Output, 0x40, 0x50);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_11_Error userData2Compare = new UserData_11_Error(eErrorCode.DataOutOfRange, 0x99);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different representation type - otherwise as identical as possible
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
												userData.LowByte, userData.HighByte, 0x33);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.LowByte, userData.HighByte);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different device
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements((byte)(userData.Device - 1), userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.LowByte, userData.HighByte);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, (byte)(userData.Address - 1), userData.AddressAddOn, userData.AddressExtension,
									userData.LowByte, userData.HighByte);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different AddressAddOn
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, (byte)(userData.AddressAddOn - 1), userData.AddressExtension,
									userData.LowByte, userData.HighByte);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address extension
				eAddressExtension_1 addExt = eAddressExtension_1.Disruption;
				if (userData.AddressExtension == eAddressExtension_1.Disruption)
				{
					addExt = eAddressExtension_1.Input;
				}
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, addExt,
									userData.LowByte, userData.HighByte);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different lowByte
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									(byte) (userData.LowByte + 0x10), userData.HighByte);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different highByte
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.LowByte, (byte) (userData.HighByte + 0x02));
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test03_Equals_RepType03()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Output, 0x40, 0x50, 0x60);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_11_Error userData2Compare = new UserData_11_Error(eErrorCode.DataOutOfRange, 0x99);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different representation type - otherwise as identical as possible
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
												userData.Byte01, userData.Byte02);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.Byte01, userData.Byte02, userData.Byte03);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different device
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements((byte)(userData.Device - 1), userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.Byte01, userData.Byte02, userData.Byte03);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, (byte)(userData.Address - 1), userData.AddressAddOn, userData.AddressExtension,
									userData.LowByte, userData.HighByte);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different AddressAddOn
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, (byte)(userData.AddressAddOn - 1), userData.AddressExtension,
									userData.Byte01, userData.Byte02, userData.Byte03);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address extension
				eAddressExtension_1 addExt = eAddressExtension_1.Disruption;
				if (userData.AddressExtension == eAddressExtension_1.Disruption)
				{
					addExt = eAddressExtension_1.Input;
				}
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, addExt,
									userData.Byte01, userData.Byte02, userData.Byte03);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different Byte01
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									(byte)(userData.Byte01 + 0x10), userData.Byte02, userData.Byte03);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different Byte02
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.Byte01, (byte)(userData.Byte02 + 0x02), userData.Byte03);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different Byte03
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.Byte01, userData.Byte02, (byte)(userData.Byte03 + 0x02));
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test04_Equals_RepTypeFree()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Output, 0xf1, new byte[] { 0x05, 0x15, 0x25 } );

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_11_Error userData2Compare = new UserData_11_Error(eErrorCode.DataOutOfRange, 0x99);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different representation type - otherwise as identical as possible
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
												userData.FreeCodeByte, userData.Byte02);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.FreeCodeByte, userData.GetCopyOfFreeBytes());
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different device
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements((byte)(userData.Device - 1), userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.FreeCodeByte, userData.GetCopyOfFreeBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, (byte)(userData.Address - 1), userData.AddressAddOn, userData.AddressExtension,
									userData.FreeCodeByte, userData.GetCopyOfFreeBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different AddressAddOn
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, (byte)(userData.AddressAddOn - 1), userData.AddressExtension,
									userData.FreeCodeByte, userData.GetCopyOfFreeBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address extension
				eAddressExtension_1 addExt = eAddressExtension_1.Disruption;
				if (userData.AddressExtension == eAddressExtension_1.Disruption)
				{
					addExt = eAddressExtension_1.Input;
				}
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, addExt,
									userData.FreeCodeByte, userData.GetCopyOfFreeBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different FreeCodeByte
				byte freeCodeByteDiff = 0xf0;
				if (userData.FreeCodeByte == 0xf0)
				{
					freeCodeByteDiff = 0xf1;
				}
				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									freeCodeByteDiff, userData.GetCopyOfFreeBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different free code bytes - one more member
				byte[] freeBytesOriginal = userData.GetCopyOfFreeBytes();
				byte[] freeBytesDiff = new byte[freeBytesOriginal.Length + 1];
				for (int index = 0; index < freeBytesOriginal.Length; index++)
				{
					freeBytesDiff[index] = freeBytesOriginal[index];
				}
				freeBytesDiff[freeBytesOriginal.Length] = 0x33;

				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.FreeCodeByte, freeBytesDiff);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different free code bytes - one changed member
				byte[] freeBytesOriginal = userData.GetCopyOfFreeBytes();
				byte[] freeBytesDiff = new byte[freeBytesOriginal.Length];
				for (int index = 0; index < freeBytesOriginal.Length; index++)
				{
					freeBytesDiff[index] = freeBytesOriginal[index];
				}
				if (freeBytesOriginal.Length > 0)
				{
					freeBytesDiff[freeBytesOriginal.Length - 1] = (byte) (freeBytesDiff[freeBytesOriginal.Length - 1] + 1);
				}

				UserData_30_Measurements userData2Compare = new UserData_30_Measurements(userData.Device, userData.Address, userData.AddressAddOn, userData.AddressExtension,
									userData.Byte01, userData.Byte02, (byte)(userData.Byte03 + 0x02));
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		#endregion equals

		#region get hash code

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test10_GetHashCode_RepType01()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Output, eMeasurementType.Temperature, 6.5);
			int hashCode = userData.GetHashCode();
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test11_GetHashCode_RepType02()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Output, 0xff, 0x80);
			int hashCode = userData.GetHashCode();
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test12_GetHashCode_RepType03()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Disruption, 0xff, 0x80, 0x40);
			int hashCode = userData.GetHashCode();
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test13_GetHashCode_RepTypeFree()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Input, 0xff, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 } );
			int hashCode = userData.GetHashCode();
		}

		#endregion get hash code

		#region ToString

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test20_ToString_RepType01()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Output, eMeasurementType.Temperature, 6.5);
			string stringResult = userData.ToString();
			Assert.IsNotNull(stringResult);
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test21_ToString_RepType02()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Output, 0xff, 0x80);
			string stringResult = userData.ToString();
			Assert.IsNotNull(stringResult);
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test22_ToString_RepType03()
		{
			UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Disruption, 0xff, 0x80, 0x40);
			string stringResult = userData.ToString();
			Assert.IsNotNull(stringResult);
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test23_ToString_RepTypeFree()
		{
			{
				UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Input, 0xff, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				UserData_30_Measurements userData = new UserData_30_Measurements(0x01, 0x02, 0x03, eAddressExtension_1.Input, 0xf5, null);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}
		}

		#endregion ToString

	}
}
